﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Engine.Classes {
    import Engine.Interfaces.*;
    import Engine.Helpers.*;

	/**
	 *	表示SavedObject的集合，此外还包括deletionList和animationBuckets 
	 */
    public class PositionedObjectContainer extends SavedObject {

        protected var m_redrawLock:int;
        protected var m_children:Array;
        private var m_allDescendents:Array;
        private var m_allDescendentsDirty:Boolean = true;
        protected var m_deletionList:Array;
        protected var m_size:IntVector2;
        protected var m_animationBuckets:Array;

        public function PositionedObjectContainer(_arg1:int, _arg2:int){
            this.m_children = new Array();
            this.m_allDescendents = new Array();
            this.m_deletionList = new Array();
            this.m_size = new IntVector2();
            this.m_animationBuckets = new Array();
            super();
            this.m_size.x = _arg1;
            this.m_size.y = _arg2;
            var _local3:Number = 0;
            while (_local3 < 100) {
                this.m_animationBuckets[_local3] = new Array();
                _local3++;
            };
        }
        override public function getSaveObject():Object{
            var _local4:Object;
            var _local1:Object = super.getSaveObject();
            var _local2:Array = new Array();
            var _local3:int;
            while (_local3 < this.m_children.length) {
                _local4 = this.m_children[_local3].getSaveObject();
                if (_local4 != null){
                    _local2.push(this.m_children[_local3].getSaveObject());
                };
                _local3++;
            };
            _local1.objects = _local2;
            return (_local1);
        }
        public function setGridSize(_arg1:int, _arg2:int):void{
            this.m_size.x = _arg1;
            this.m_size.y = _arg2;
        }
        public function getGridWidth():int{
            return (this.m_size.x);
        }
        public function getGridHeight():int{
            return (this.m_size.y);
        }
        public function lockRedraw():void{
            this.m_redrawLock++;
        }
        public function unlockRedraw():void{
            this.m_redrawLock--;
            if (this.isRedrawLocked() == false){
                this.conditionallyRedrawAllObjects();
            };
        }
        final public function getObjects():Array{
            var _local1:int;
            if (this.m_allDescendentsDirty){
                this.m_allDescendents = [];
                _local1 = 0;
                while (_local1 < this.m_children.length) {
                    if ((this.m_children[_local1] is IEngineObject)){
                        this.m_allDescendents = this.m_allDescendents.concat(this.m_children[_local1].children);
                    };
                    _local1++;
                };
                this.m_allDescendentsDirty = false;
            };
            return (this.m_allDescendents);
        }
        final public function setObjectsDirty():void{
            this.m_allDescendentsDirty = true;
        }
        public function isRedrawLocked():Boolean{
            return (!((this.m_redrawLock == 0)));
        }
        public function conditionallyRedrawAllObjects():void{
        }
        public function getNumObjects():int{
            return (this.getObjects().length);
        }
        public function getNumVisibleObjects():int{
            var _local4:PositionedObject;
            var _local1:int;
            var _local2:Array = this.getObjects();
            var _local3:int;
            while (_local3 < _local2.length) {
                _local4 = (_local2[_local3] as PositionedObject);
                if (((_local4) && (_local4.isVisible()))){
                    _local1++;
                };
                _local3++;
            };
            return (_local1);
        }
        public function addToDeletionList(_arg1:PositionedObject):void{
            if (this.m_deletionList.indexOf(_arg1) == -1){
                this.m_deletionList.push(_arg1);
            };
        }
        public function removeFromDeletionList(_arg1:PositionedObject):void{
            var _local2:int = this.m_deletionList.indexOf(_arg1);
            if (_local2 != -1){
                this.m_deletionList.splice(_local2, 1);
            };
        }
        public function get animationBuckets():Array{
            return (this.m_animationBuckets);
        }
        public function resetBuckets():void{
            this.m_animationBuckets = new Array();
            var _local1:Number = 0;
            while (_local1 < 100) {
                this.m_animationBuckets[_local1] = new Array();
                _local1++;
            };
        }
        public function insertItemIntoAnimationBucket(_arg1:PositionedObject):int{
            var _local2:int = Math.floor((Math.random() * 100));
            var _local3:Array = this.m_animationBuckets[_local2];
            _local3.push(_arg1);
            return (_local2);
        }
        public function removeItemFromAnimationBucket(_arg1:PositionedObject, _arg2:int):void{
            var _local3:Array = this.m_animationBuckets[_arg2];
            var _local4:int = _local3.indexOf(_arg1);
            _local3.splice(_local4, 1);
        }

    }
}//package Engine.Classes 
